package com.gl.goods.ui.main.mvp.home;

import com.gl.goods.base.BasePresenter;
import com.gl.goods.net.GetResultErrorMessage;
import com.gl.goods.net.RxScheduler;
import com.gl.goods.ui.main.bean.HomeAdvertisementListBean;

import java.util.Map;

import io.reactivex.functions.Consumer;

/**
 * Time; 2020/11/13
 * Author: hmc
 * Description:
 */
public class HomePresenter extends BasePresenter<HomeContract.View> implements HomeContract.Presenter {
    private HomeContract.Model model;

    public HomePresenter() {
        this.model = new HomeModel();
    }

    @Override
    public void getAdvertisementList() {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getAdvertisementList()
                .compose(RxScheduler.<HomeAdvertisementListBean>Flo_io_main())
                .as(mView.<HomeAdvertisementListBean>bindAutoDispose())
                .subscribe(new Consumer<HomeAdvertisementListBean>() {
                    @Override
                    public void accept(HomeAdvertisementListBean bean) throws Exception {
                        mView.getAdvertisementSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
//                        mView.showErrorMessage(GetResultErrorMessage.getInstance().GetResultErrorMessage(throwable));
                        mView.hideLoading();
                    }
                });
    }
}
